class Solution:
    def maxSatisfied(self, customers: list, grumpy: list, X: int) -> int:
        res = 0
        for i in range(len(customers)):
            if grumpy[i] == 0:
                res += customers[i]
                customers[i] = 0

        m = 0
        cur = 0
        left = 0
        right = 0
        while right < len(customers):
            cur += customers[right]
            if right - left >= X:
                cur -= customers[left]
                left += 1
            right += 1
            m = max(cur, m)

        return res + m


if __name__ == "__main__":
    print(Solution().maxSatisfied(
        customers=[1, 0, 1, 2, 1, 1, 7, 5],
        grumpy=[0, 1, 0, 1, 0, 1, 0, 1],
        X=3))
